<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_M_MAP_GROUP_SHOP extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table  = "M_MAP_GROUP_SHOP";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey   = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "id";
	 
	 protected $_cols  = array(
		"map_no"          => array(AOKI_VARTYPE_STR),
		"matrix_cd"       => array(AOKI_VARTYPE_STR),
		"shop_cd"         => array(AOKI_VARTYPE_STR),
		"group_no"        => array(AOKI_VARTYPE_STR),
		"mark"            => array(AOKI_VARTYPE_STR),
		"comm"            => array(AOKI_VARTYPE_STR),
		"congruent_map"   => array(AOKI_VARTYPE_STR),
		"congruent_ins"   => array(AOKI_VARTYPE_STR),
		"ins_load_ratio"  => array(AOKI_VARTYPE_STR),
		"memo"            => array(AOKI_VARTYPE_STR),
		"dummy"           => array(AOKI_VARTYPE_STR),
		"service"         => array(AOKI_VARTYPE_STR),
		"work_time"       => array(AOKI_VARTYPE_STR)
	 );
	
	 protected $_checks  = array(
		"map_no"          => array( "EXIST", "NUM" ),
		"matrix_cd"       => array( "EXIST" ),
		"seq"             => array( "NUM" ),
		"shop_cd"         => array( "EXIST" ),
		"ins_load_ratio"  => array( "NUM" )
	 );
	
	 //maxlength 
	 protected $_maxlens  = array(	
	 	"map_no"      => 10,
		"matrix_cd"   => 9
	 );
	 
	 protected $_errorfields  = array(
		"map_no"               => "マップNO",
		"matrix_cd"            => "マトリックスコード",		
		"shop_cd"              => "店舗コード",
		"ins_load_ratio"       => "折込負担比率",
		"congruent_ins"        => "合同折込",
		"mark"                 => "親店舗",
		"group_no"             => "マップグループNO",
		
		
	 );
	 
 	 public function get_errorfields() {
		return $this->_errorfields ;
	}
	
/*
	 public function search($where ,&$page = NULL ){	
		$sql = "SELECT a.*,(select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a ";
		return  parent::search($where ,$page ,$sql);
	}
*/
	 public function search($where ,&$page = NULL ){
		//$fromtable = "  from M_MAP_GROUP_SHOP a  inner join (select cast(shop_cd as char(5)) as shop_cd, shop_name,smx from M_SHOP union  all select mservice_cd as shop_cd, mservice_name as shop_name, '' as smx from M_MAP_SERVICE) b  on  a.shop_cd = b.shop_cd ";
		$fromtable = "  from M_MAP_GROUP_SHOP a  inner join (select cast(shop_cd as char(5)) as shop_cd, shop_name from M_SHOP union  all select mservice_cd as shop_cd, mservice_name as shop_name from M_MAP_SERVICE) b  on  a.shop_cd = b.shop_cd ";
		//$sql       = " select a.*,b.shop_name,b.smx ".$fromtable ;
		$sql       = " select a.*,b.shop_name ".$fromtable ;
		$sqlCount  = " SELECT count(*) AS cnt ".$fromtable ;
		$orderby   = "  a.seq,a.shop_cd ";
		return  parent::search($where, $page, $sql, $sqlCount,$orderby) ;
	}
	
	 public function getMapShopHead( $matrix_cd,$map_no ){
		$fromtable = " from M_MAP_GROUP_WEEK  a  inner join M_MATRIX_TERM b  on  a.matrix_cd = b.matrix_cd  inner join M_MAP_GROUP c  on  a.map_no = c.map_no ";
		$where     = " where  a.matrix_cd = '{$matrix_cd}' and  a.map_no = '{$map_no}' ";
		$sql       = "select a.u_time,b.year4,b.week_cd, b.week_seq, c.sort,c.media_name  ".$fromtable.$where ;
		
		$this->_db->query( $sql );
		if( $this->_db->num_rows() ){
			$row  = $this->_db->fetch();
			return $row;
			
		}else{
			return  null;
		}
	}
		
	
	
}


?>